package GUI;

import javax.swing.*;

import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
/**
 * This class creates instance of loginPanel	
 * to display when needed
 * @author 
 *
 */
public class Login extends JPanel{
	private static final long serialVersionUID = 1L;
	private JPasswordField password;
	private JButton subButton;
	private JTextField userName;
	private JLabel iconlabel;
	private JLabel lblLogin;
	
	/**
	 * the constructor
	 */
	public Login() {
		super();
		//pass = new JTextArea();
		password = new JPasswordField();
		password.setText("password");
		password.setEnabled(false);
		password.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				password.setText("");
				password.setEnabled(true);
				if(password.getText().toString().equals("password")||userName.getText().toString().equals("user name"))
					subButton.setEnabled(false);
				else
					subButton.setEnabled(true);
				
			}
		});
		subButton = new JButton("LOGIN");
		
		subButton.setEnabled(false);
		userName = new JTextField();
		userName.setText("user name");
		userName.setEnabled(false);
		userName.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				userName.setText("");
				userName.setEnabled(true);
				if(password.getText().toString().equals("password")||userName.getText().toString().equals("user name"))
					subButton.setEnabled(false);
				else
					subButton.setEnabled(true);
				
			}
		});
		userName.addKeyListener(new KeyAdapter() {
			public void keyTyped(KeyEvent evt) {
				char c = evt.getKeyChar();
				if(!(Character.isDigit(c) || (c==KeyEvent.VK_BACK_SPACE) || (c==KeyEvent.VK_DELETE))){
					getToolkit().beep();
					evt.consume();
				}
			}
		});
	
		initialize();
	}//end constructor
	
	/**
	 * This method initializes loginPanel
	 */
	public void initialize(){
		
		JLabel lblUserName = new JLabel("User Name:");
		lblUserName.setForeground(Color.WHITE);
		lblUserName.setFont(new Font("Tahoma", Font.BOLD, 12));
		lblUserName.setBounds(140, 143, 86, 50);
		add(lblUserName);
		
		JLabel lblPassword = new JLabel("Password:");
		lblPassword.setForeground(Color.WHITE);
		lblPassword.setFont(new Font("Tahoma", Font.BOLD, 12));
		lblPassword.setBounds(140, 220, 81, 60);
		add(lblPassword);
		
		
		password.setBounds(244, 231, 207, 40);
		add(password);
		password.setColumns(10);
		
		subButton.setIcon(new ImageIcon(Login.class.getResource("/resources/my_login.png"))); 
		subButton.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 12));
		subButton.setBounds(288, 310, 117, 65);
		add(subButton);
		
		setLayout(null);
		setSize(new Dimension(786, 500));	
		
		
	
		userName.setBounds(244, 149, 207, 40);
		add(userName);
		userName.setColumns(10);
		
		ImageIcon LOGOImageIcon = new ImageIcon(getClass().getClassLoader().getResource("resources/camera-background3.png"));
		ImageIcon LOGO = new ImageIcon (LOGOImageIcon.getImage().getScaledInstance(-1, -1, java.awt.Image.SCALE_SMOOTH));
		
		lblLogin = new JLabel("LOGIN");
		lblLogin.setFont(new Font("Tahoma", Font.BOLD, 16));
		lblLogin.setForeground(new Color(0, 204, 255));
		lblLogin.setBounds(10, 11, 108, 25);
		add(lblLogin);
		
		iconlabel = new JLabel("");
		iconlabel.setFont(new Font("Tahoma", Font.PLAIN, 14));
		iconlabel.setIcon(LOGO);
		iconlabel.setBounds(0, 0, 786, 500);
		add(iconlabel);
	}//end initialize
	
	/**
	 * 
	 * @return JTextField with the user name
	 */
	public JTextField get_userName(){
		return userName;
	}
	/**
	 * 
	 * @param userName to set the user-name textArea
	 */
	public void set_userName(String text){
		userName.setText(text);
	}
	/**
	 * 
	 * @return  the password
	 */
	
	public JPasswordField get_password() {	
		return password;
	}
	/**
	 * 
	 * @param password to set the password field
	 */
	public void set_password(String text1){
		password.setText(text1);
	}
	/**
	 * 
	 * @return the submit button
	 */
	public JButton getSubButt(){
		return subButton;
	}


}//end Login
	